/*
 * claplan_target.cc
 *
 *  Created on: 2 Nov 2013
 *      Author: Tom Vercauteren
 */

#include "claplan_target.h"
#include <ostream>
#include <string>

#include "claplan_print.h"

using std::string;
using std::endl;

ClaplanTarget::ClaplanTarget() :
		name(""), tcp_model(""), tcp_name(""), impf(0), pf_inhom(0), pf_rms(0), tracer(
				""), impf_pet(0), rimpf_petd(0), pet_low(0), dose_low(0), pet_high(
				0), dose_high(0), c_pf_inhom(0), c_pf_rms(0)
{
	pf_rmsdiffs[0] = 0;
	pf_rmsdiffs[1] = 0;

	pf_ihlf[0] = 0;
	pf_ihlf[1] = 0;
	pf_ihlf[2] = 0;

	pfs_olf[0] = 0;
	pfs_olf[1] = 0;
	pfs_olf[2] = 0;

	cmi[0] = 0;
	cmi[1] = 0;

	mask.name =0;
	mask.tcp_model =0;
	mask.tcp_name =0;
	mask.impf =0;
	mask.pf_inhom =0;
	mask.pf_rms =0;
	mask.pf_rmsdiff =0;
	mask.dvhps =0;
	mask.pf_ihlf =0;
	mask.pfs_olf =0;
	mask.tracer =0;
	mask.impf_pet =0;
	mask.rimpf_petd =0;
	mask.pet_low =0;
	mask.dose_low =0;
	mask.pet_high =0;
	mask.dose_high =0;
	mask.c_pf_inhom =0;
	mask.c_pf_rms =0;
	mask.cmi =0;
}

ClaplanTarget::ClaplanTarget(const ClaplanTarget &ct)
{
	if (this != &ct) *this = ct;
}

ClaplanTarget::~ClaplanTarget()
{

}
ClaplanTarget& ClaplanTarget::operator=(const ClaplanTarget &ct)
{
	if (this != &ct)
	{
		name = ct.name;
		tcp_model = ct.tcp_model;
		tcp_name = ct.tcp_name;
		impf = ct.impf;

		pf_inhom = ct.pf_inhom;
		pf_rms = ct.pf_rms;

		unsigned i;
		for (i = 0; i < 2; i++)
			pf_rmsdiffs[i] = ct.pf_rmsdiffs[i];

		dvhps = ct.dvhps;

		for (i = 0; i < 3; i++)
		{
			pf_ihlf[i] = ct.pf_ihlf[i];
			pfs_olf[i] = ct.pfs_olf[i];
		}

		tracer = ct.tracer;
		impf_pet = ct.impf_pet;
		rimpf_petd = ct.rimpf_petd;
		pet_low = ct.pet_low;
		dose_low = ct.dose_low;
		pet_high = ct.pet_high;
		dose_high = ct.dose_high;

		c_pf_inhom = ct.c_pf_inhom;
		c_pf_rms = ct.c_pf_rms;

		for (i = 0; i < 2; i++)
			cmi[i] = ct.cmi[i];

		mask = ct.mask;
	}
	return *this;
}

double ClaplanTarget::getCPfInhom() const
{
	return c_pf_inhom;
}

void ClaplanTarget::setCPfInhom(double c_pf_inhom)
{
	this->c_pf_inhom = c_pf_inhom;
	mask.c_pf_inhom = 1;
}

void ClaplanTarget::unsetCPfInhom()
{
	this->c_pf_inhom = 0;
	mask.c_pf_inhom = 0;
}
unsigned char ClaplanTarget::isCPfInhomSet() const
{
	return mask.c_pf_inhom;
}

double ClaplanTarget::getCPfRms() const
{
	return c_pf_rms;
}

void ClaplanTarget::setCPfRms(double c_pf_rms)
{
	this->c_pf_rms = c_pf_rms;
	mask.c_pf_rms = 1;
}

void ClaplanTarget::unsetCPfRms()
{
	this->c_pf_rms = 0;
	mask.c_pf_rms = 0;
}
unsigned char ClaplanTarget::isCPfRmsSet() const
{
	return mask.c_pf_rms;
}

void ClaplanTarget::setCmi(const double *cmi)
{
	for (unsigned i = 0; i < 2; i++)
		this->cmi[i] = cmi[i];
	mask.cmi = 1;
}

const double* ClaplanTarget::getCmi() const
{
	return cmi;
}

void ClaplanTarget::unsetCmi()
{
	for (unsigned i = 0; i < 2; i++)
		this->cmi[i] = 0;
	mask.pf_rmsdiff = 0;
}

unsigned char ClaplanTarget::isCmiSet() const
{
	return mask.cmi;
}

double ClaplanTarget::getDoseHigh() const
{
	return dose_high;
}

void ClaplanTarget::setDoseHigh(double doseHigh)
{
	dose_high = doseHigh;
	mask.dose_high = 1;
}

void ClaplanTarget::unsetDoseHigh()
{
	dose_high = 0;
	mask.dose_high = 0;
}

unsigned char ClaplanTarget::isDoseHighSet() const
{
	return mask.dose_high;
}

double ClaplanTarget::getDoseLow() const
{
	return dose_low;
}

void ClaplanTarget::setDoseLow(double doseLow)
{
	dose_low = doseLow;
	mask.dose_low = 1;
}

void ClaplanTarget::unsetDoseLow()
{
	dose_low = 0;
	mask.dose_low = 0;
}

unsigned char ClaplanTarget::isDoseLowSet() const
{
	return mask.dose_low;
}

double ClaplanTarget::getImpf() const
{
	return impf;
}

void ClaplanTarget::setImpf(double impf)
{
	this->impf = impf;
	mask.impf = 1;
}

void ClaplanTarget::unsetImpf()
{
	impf = 0;
	mask.impf = 0;
}

unsigned char ClaplanTarget::isImpfSet() const
{
	return mask.impf;
}

double ClaplanTarget::getImpfPet() const
{
	return impf_pet;
}

void ClaplanTarget::setImpfPet(double impfPet)
{
	impf_pet = impfPet;
	mask.impf_pet = 1;
}

void ClaplanTarget::unsetImpfPet()
{
	impf_pet = 0;
	mask.impf_pet = 0;
}

unsigned char ClaplanTarget::isImpfPetSet() const
{
	return mask.impf_pet;
}

const std::string& ClaplanTarget::getName() const
{
	return name;
}

void ClaplanTarget::setName(const std::string& name)
{
	this->name = name;
	mask.name = 1;
}

void ClaplanTarget::unsetName()
{
	name = "";
	mask.name = 0;
}

unsigned char ClaplanTarget::isNameSet() const
{
	return mask.name;
}

double ClaplanTarget::getPetHigh() const
{
	return pet_high;
}

void ClaplanTarget::setPetHigh(double petHigh)
{
	pet_high = petHigh;
	mask.pet_high = 1;
}

void ClaplanTarget::unsetPetHigh()
{
	pet_high = 0;
	mask.pet_high = 0;
}

unsigned char ClaplanTarget::isPetHighSet() const
{
	return mask.pet_high;
}

double ClaplanTarget::getPetLow() const
{
	return pet_low;
}

void ClaplanTarget::setPetLow(double petLow)
{
	pet_low = petLow;
	mask.pet_low = 1;
}

void ClaplanTarget::unsetPetLow()
{
	pet_low = 0;
	mask.pet_low = 0;
}

unsigned char ClaplanTarget::isPetLowSet() const
{
	return mask.pet_low;
}

void ClaplanTarget::setPfIhlf(const double *pf_ihlf)
{
	for (unsigned i = 0; i < 3; i++)
		this->pf_ihlf[i] = pf_ihlf[i];
	mask.pf_ihlf = 1;
}

const double* ClaplanTarget::getPfIhlf() const
{
	return pf_ihlf;
}

void ClaplanTarget::unsetPfIhlf()
{
	for (unsigned i = 0; i < 3; i++)
		this->pf_ihlf[i] = 0;
	mask.pf_ihlf = 0;
}

unsigned char ClaplanTarget::isPfIhlfSet() const
{
	return mask.pf_ihlf;
}

double ClaplanTarget::getPfInhom() const
{
	return pf_inhom;
}

void ClaplanTarget::setPfInhom(double pfInhom)
{
	pf_inhom = pfInhom;
	mask.pf_inhom = 1;
}

void ClaplanTarget::unsetPfInhom()
{
	pf_inhom = 0;
	mask.pf_inhom = 0;
}

unsigned char ClaplanTarget::isPfInhomSet() const
{
	return mask.pf_inhom;
}

double ClaplanTarget::getPfRms() const
{
	return pf_rms;
}

void ClaplanTarget::setPfRms(double pf_rms)
{
	this->pf_rms = pf_rms;
	mask.pf_rms = 1;
}

void ClaplanTarget::unsetPfRms()
{
	pf_rms = 0;
	mask.pf_rms = 0;
}

unsigned char ClaplanTarget::isPfRmsSet() const
{
	return mask.pf_rms;
}

const double* ClaplanTarget::getPfRmsdiffs() const
{
	return pf_rmsdiffs;
}

void ClaplanTarget::setPfRmsdiffs(const double *pf_rmsdiffs)
{
	for (unsigned i = 0; i < 2; i++)
		this->pf_rmsdiffs[i] = pf_rmsdiffs[i];
	mask.pf_rmsdiff = 1;
}

void ClaplanTarget::unsetPfRmsdiffs()
{
	for (unsigned i = 0; i < 2; i++)
		this->pf_rmsdiffs[i] = 0;
	mask.pf_rmsdiff = 0;
}

unsigned char ClaplanTarget::isPfRmsdiffsSet() const
{
	return mask.pf_rmsdiff;
}

void ClaplanTarget::setPfsOlf(const double *pfs_olf)
{
	for (unsigned i = 0; i < 3; i++)
		this->pfs_olf[i] = pfs_olf[i];
	mask.pfs_olf = 1;
}

const double* ClaplanTarget::getPfsOlf() const
{
	return pfs_olf;
}

void ClaplanTarget::unsetPfsOlf()
{
	for (unsigned i = 0; i < 3; i++)
		this->pfs_olf[i] = 0;
	mask.pfs_olf = 0;
}

unsigned char ClaplanTarget::isPfsOlfsSet() const
{
	return mask.pfs_olf;
}

double ClaplanTarget::getRimpfPetd() const
{
	return rimpf_petd;
}

void ClaplanTarget::setRimpfPetd(double rimpfPetd)
{
	rimpf_petd = rimpfPetd;
	mask.rimpf_petd = 1;
}

void ClaplanTarget::unsetRimpfPetd()
{
	rimpf_petd = 0;
	mask.rimpf_petd = 0;
}

unsigned char ClaplanTarget::isRimpfPetdSet() const
{
	return mask.rimpf_petd;
}

const std::string& ClaplanTarget::getTcpModel() const
{
	return tcp_model;
}

void ClaplanTarget::setTcpModel(const std::string& tcpModel)
{
	tcp_model = tcpModel;
	mask.tcp_model = 1;
}

void ClaplanTarget::unsetTcpModel()
{
	tcp_model = "";
	mask.tcp_model = 0;
}

unsigned char ClaplanTarget::isTcpModelSet() const
{
	return mask.tcp_model;
}

const std::string& ClaplanTarget::getTcpName() const
{
	return tcp_name;
}

void ClaplanTarget::setTcpName(const std::string& tcpName)
{
	tcp_name = tcpName;
	mask.tcp_name = 1;
}

void ClaplanTarget::unsetTcpName()
{
	tcp_name = "";
	mask.tcp_name = 0;
}

unsigned char ClaplanTarget::isTcpNameSet() const
{
	return mask.tcp_name;
}

const std::string& ClaplanTarget::getTracer() const
{
	return tracer;
}

void ClaplanTarget::setTracer(const std::string& tracer)
{
	this->tracer = tracer;
	mask.tracer = 1;
}

void ClaplanTarget::unsetTracer()
{
	tracer = "";
	mask.tracer = 0;
}

unsigned char ClaplanTarget::isTracerSet() const
{
	return mask.tracer;
}

std::ostream & operator<<(std::ostream & os, const ClaplanTarget &target)
{
	os << "target :" << endl;
	if (target.isNameSet() & 1)
		print_kv<string, string>(os, "anastruct", target.getName());
	if (target.isTcpModelSet() & 1)
		print_kv<string, string>(os, "TCP_model", target.getTcpModel());
	if (target.isTcpNameSet() & 1)
		print_kv<string, string>(os, "TCP_name", target.getTcpName());
	os << endl;
	if (target.isImpfSet() & 1)
		print_kv<string, double>(os, "impf", target.getImpf());

	if (target.isPfInhomSet() & 1)
		print_kv<string, double>(os, "pf_inhom", target.getPfInhom());
	if (target.isPfRmsSet() & 1)
		print_kv<string, double>(os, "pf_rms", target.getPfRms());
	if (target.isPfRmsdiffsSet() & 1)
		print_kv<string, double>(os, "pf_rmsdiffs", target.getPfRmsdiffs(), 2);
	os << endl;
	if (target.isPfIhlfSet() & 1)
		print_kv<string, double>(os, "pf_ihlf", target.getPfIhlf(), 3);
	for (unsigned i = 0; i < target.dvhps.size(); i++)
		os << target.dvhps.at(i);
	if (target.isPfsOlfsSet() & 1)
		print_kv<string, double>(os, "pfs_olf", target.getPfsOlf(), 3);

	os << endl;
	if (target.isTracerSet() & 1)
		print_kv<string, string>(os, "tracer", target.getTracer());
	if (target.isImpfPetSet() & 1)
		print_kv<string, double>(os, "impf_pet", target.getImpfPet());
	if (target.isRimpfPetdSet() & 1)
		print_kv<string, double>(os, "rimpf_petd", target.getRimpfPetd());
	if (target.isPetLowSet() & 1)
		print_kv<string, double>(os, "pet_low", target.getPetLow());
	if (target.isDoseLowSet() & 1)
		print_kv<string, double>(os, "dose_low", target.getDoseLow());
	if (target.isPetHighSet() & 1)
		print_kv<string, double>(os, "pet_high", target.getPetHigh());
	if (target.isDoseHighSet() & 1)
		print_kv<string, double>(os, "dose_high", target.getDoseHigh());
	os << endl;
	if (target.isCPfInhomSet() & 1)
		print_kv<string, double>(os, "c_pf_inhom", target.getCPfInhom());
	if (target.isCPfRmsSet() & 1)
		print_kv<string, double>(os, "c_pf_rms", target.getCPfRms());
	os << endl;
	if (target.isCmiSet() & 1)
		print_kv<string, double>(os, "cmi", target.getCmi(), 2);
	return os << endl;
}
